<?php
session_start();
include("load-settings.php");

if(!isset($_SESSION['user']))
	header("Location: login.php");

$user = mysql_real_escape_string($_SESSION['user']);
$result = mysql_query("SELECT * FROM user WHERE id = $user");
$row = mysql_fetch_array($result);

if($row['type'] != 2)
	header("Location: home.php");

$user = mysql_real_escape_string($_POST['id']);
$username = mysql_real_escape_string($_POST['username']);
$paypal = mysql_real_escape_string($_POST['paypal']);
$summoner = mysql_real_escape_string($_POST['summoner']);
//$region = mysql_real_escape_string($_POST['region']);

$result = mysql_query("SELECT * FROM user WHERE id = $user");

if(mysql_num_rows($result) == 0)
	header("Location: edit-user.php");

$result = mysql_query("SELECT * FROM user WHERE paypal = '$paypal'");

if(mysql_num_rows($result) != 0)
	header("Location: edit-user.php");

mysql_query("UPDATE user SET username = '$username', paypal = '$paypal', summoner = '$summoner' WHERE id = $user");

header("Location: edit-user.php");

?>